#include<iostream>

#include<queue>
#include<vector>
using namespace std;
const int N=1e5+10;
long long nums[N];
int main()
{
	int n;cin>>n;
	priority_queue<long long,vector<long long>,
		greater<long long>> q;
	for(int i=1;i<=n;i++)
	{
		long long x;cin>>x;
		q.push(x);
	}
	long long ret=0;
	while(q.size()>1)
	{
		long long a=q.top();q.pop();
		long long b=q.top();q.pop();
		long long sum=a+b;
		ret+=(sum);
		q.push(sum);
	}
	cout<<ret<<endl;	
}